package com.tron.task;

import cn.hutool.json.JSONUtil;
import com.tron.controller.account.AccountController;
import com.tron.dto.R;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
public class MyTask1 extends QuartzJobBean {

    //验证是否成功可以注入service   之前在ssm当中需要额外进行配置
    @Autowired
    private AccountController controller;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        R<?> account = controller.createAccount(1);
        System.out.println(account);
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        String json = (String)jobDataMap.get("json");
        Map bean = JSONUtil.toBean(json, Map.class);
        String key = (String)bean.get("key");
        System.out.println(key);
        System.out.println(jobDataMap);
        //TODO 这里写定时任务的执行逻辑
        System.out.println("动态的定时任务执行时间："+new Date().toLocaleString());
    }
}